home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / utils / file / logiso.000 / logiso / Utils / ksh_fns < prev    next >
Encoding:
Text File  |  1995-03-24  |  1.1 KB  |  44 lines

  1.  
  2. # (C) Copyright 1995 by Michael Coulter.  All rights reserved.
  3. ##########################################################################
  4. # Functions:
  5.     # check_return expected_value exit_value exit_message
  6.     # check_cmd function: check_cmd exit_status cmd arg...
  7.     # report_error expected_status message
  8.  
  9.     # USAGE: check_return expected_value exit_value exit_message
  10.     function check_return
  11.     {
  12.     RETURN_STATUS=$?
  13.     if [ "$RETURN_STATUS" -ne "$1" ]
  14.     then
  15.         echo "Expected status $1 got ${RETURN_STATUS}." >&2
  16.         echo "$3" >&2
  17.         exit "$2"
  18.     fi
  19.     }
  20.  
  21.     # check_cmd function: check_cmd exit_status cmd arg...
  22.     #
  23.     function check_cmd
  24.     {
  25.         EXIT_STATUS="$1"; shift
  26.         COMMAND="$@"
  27.         "$@"
  28.         check_return 0 "$EXIT_STATUS" "Error with command: $COMMAND"
  29.     }
  30.  
  31.     #   report_error expected_status message
  32.     #        if $? is not expecte_status, print message to stderr and
  33.     #        increment NBR_ERRORS
  34.     function report_error
  35.     {
  36.         REPORT_ERROR_STATUS=$?
  37.         if [ $REPORT_ERROR_STATUS -ne "$1" ]
  38.         then
  39.         echo "$2" >&2
  40.         NBR_ERRORS=$$(($NBR_ERRORS + 1))
  41.         fi
  42.     }
  43.     NBR_ERRORS=0
  44.